//
//  HeadlineEyeCare.swift
//  HeadlineNews
//
//  Created by han on 2019/6/4.
//  Copyright © 2019 han. All rights reserved.
//

import UIKit

let kEyeCareMode = "kEyeCareMode"

enum HeadlineEyeCareLevel: Int {
    case `default` = 0
    case  level1 = 1
    case level2 = 2
    
    static var before = HeadlineEyeCareLevel.default
    static var current = HeadlineEyeCareLevel.default
    
    static func switchTo(_ level: HeadlineEyeCareLevel) {
        before = current
        current = level
        UserDefaults.set(level.rawValue, forKey: kEyeCareMode)
        switch level {
        case .default:EyeCareManager.shared.setEyeCare(level: 0)
        case .level1: EyeCareManager.shared.setEyeCare(level: 0.3)
        case .level2: EyeCareManager.shared.setEyeCare(level: 0.5)
      }
    }
    
    static func isEyeCareMode() -> Bool {
        return current != .default
    }
    
    //护眼模式
    //由于护眼模式需要修改keyWindow所以加载本地护眼模式时，需要设置在Active的时候
    static func initLocalEyeCareLevel() {
        let level = UserDefaults.integer(forKey: kEyeCareMode)
        switchTo(HeadlineEyeCareLevel(rawValue: level)!)
    }
}
